# -*- coding: utf8 -*-
import os
from kivy import Logger

from kivy.uix.screenmanager import ScreenManager, SlideTransition, SwapTransition, FadeTransition, WipeTransition
from kivy.core.window import Window
from EasyLangLearnButton import EasyLangLearnButtonLang

from EasyLangLearnScreen import EasyLangLearnScreenHome, EasyLangLearnScreenClassifications, EasyLangLearnScreenSetup, EasyLangLearnScreenExam


class EasyLangLearnWindow(ScreenManager):
    """Основен екран, съдържащ няколко сменящи се екрана
    - избор на език
    - избор на класификации
    - избор на настройки
    - изпит
    """

    path = "./"
    exam_options = {}
    exam = None

    __screens = ['home', 'classification', 'setup', 'exam']

    def __init__(self, path, **kwargs):
        self.path = path

        super(EasyLangLearnWindow, self).__init__(transition=SlideTransition(direction='left'))

        self.init_options()

    def init_options(self, **kwargs):
        self.exam_options = {
            'LANGUAGE': 0,
            'CLASSIFICATION': 0,
            'EXAM_TYPE': 0,
            'FROM_DATE': '',
            'TO_DATE': '',
            'CATEGORIES_INCLUDED': [],
            'CATEGORIES_EXCLUDED': [],
            'TEST_WORD_NUM': 1,
            'WORD_COUNT': 0,
            'PATH': self.path
        }

        if kwargs.has_key('LANGUAGE'):
            self.exam_options['LANGUAGE'] = kwargs['LANGUAGE']

        if kwargs.has_key('CLASSIFICATION'):
            self.exam_options['CLASSIFICATION'] = kwargs['CLASSIFICATION']

    def go_next(self, info=False):
        current_index = self.__screens.index(self.current)

        if current_index < len(self.__screens) - 1:
            if info:
                self.get_screen(self.__screens[current_index + 1]).load_data(self)

            self.transition.direction = 'left'
            self.current = self.__screens[current_index + 1]

            return True

        return False

    def go_prev(self):
        current_index = self.__screens.index(self.current)

        if current_index > 0:
            self.transition.direction = 'right'
            self.current = self.__screens[current_index - 1]

            return True

        return False

